Return to start page
Core/Interface/Struct Indicator.j
1 library AStructCoreInterfaceIndicator requires optional ALibraryCoreDebugMisc, AStructCoreGeneralHashTable
2
3 /// @todo Some dynamic members could not be dynamic!
4 /// @todo Implement as abstract struct and add child structs with various object types.
5 struct AIndicator
6 //static constant members
7 public static constant integer objectTypeImage = 0
8 public static constant integer objectTypeTextTag = 1
9 public static constant integer objectTypeUnit = 2
10 //dynamic members
11 private handle m_object
12 private integer m_objectType
13 private real m_rate //test if there are errors because it is dynamic
14 private real m_time //here it's the same
15 private real m_red //we are using BJ functions so we're calculating with per cents
16 private real m_green
17 private real m_blue
18 private real m_transparency
19 //members
20 private trigger m_refreshTrigger //= null
21 private real m_elapsedTime //= 0.00 //Vergangene Zeit
22 private boolean m_firstTime //= true
23
24 //! runtextmacro optional A_STRUCT_DEBUG("\"AIndicator\"")
25
26 //dynamic member methods
27
28 public method setObject takes handle object returns nothing
29 set this.m_object = object
30 endmethod
31
32 public method object takes nothing returns handle
33 return this.m_object
34 endmethod
35
36 public method setObjectType takes integer objectType returns nothing
37 set this.m_objectType = objectType
38 endmethod
39
40 public method objectType takes nothing returns integer
41 return this.m_objectType
42 endmethod
43
44 public method setRate takes real rate returns nothing
45 set this.m_rate = rate
46 endmethod
47
48 public method rate takes nothing returns real
49 return this.m_rate
50 endmethod
51
52 public method setTime takes real time returns nothing
53 set this.m_time = time
54 endmethod
55
56 public method time takes nothing returns real
57 return this.m_time
58 endmethod
59
60 public method setRed takes real red returns nothing
61 set this.m_red = red
62 endmethod
63
64 public method red takes nothing returns real
65 return this.m_red
66 endmethod
67
68 public method setGreen takes real green returns nothing
69 set this.m_green = green
70 endmethod
71
72 public method green takes nothing returns real
73 return this.m_green
74 endmethod
75
76 public method setBlue takes real blue returns nothing
77 set this.m_blue = blue
78 endmethod
79
80 public method blue takes nothing returns real
81 return this.m_blue
82 endmethod
83
84 public method setTransparency takes real transparency returns nothing
85 set this.m_transparency = transparency
86 endmethod
87
88 public method transparency takes nothing returns real
89 return this.m_transparency
90 endmethod
91
92 //public methods
93
94 /// Flash restarts when enabling the indicator.
95 public method enable takes boolean enable returns nothing
96 set this.m_elapsedTime = 0.0
97 call EnableTrigger(this.m_refreshTrigger)
98 endmethod
99
100 public method disable takes nothing returns nothing
101 call DisableTrigger(this.m_refreshTrigger)
102 call this.reset()
103 endmethod
104
105 //private methods
106
107 private method indicateImage takes nothing returns nothing
108 //call SetImageColorBJ(H2Image(this.m_object), this.m_red, this.m_green, this.m_blue, this.m_transparency)
109 call TriggerSleepAction(this.m_rate / 2.0)
110 //call SetImageColorBJ(H2Image(this.m_object), 100.0, 100.0, 100.0, 0.0)
111 endmethod
112
113 private method indicateTextTag takes nothing returns nothing
114 //call SetTextTagColorBJ(H2TextTag(this.m_object), this.m_red, this.m_green, this.m_blue, this.m_transparency)
115 call TriggerSleepAction(this.m_rate / 2.00)
116 //call SetTextTagColorBJ(H2TextTag(this.m_object), 100.0, 100.0, 100.0, 0.0)
117 endmethod
118
119 private method indicateUnit takes nothing returns nothing
120 //call SetUnitVertexColorBJ(H2Unit(this.m_object), this.m_red, this.m_green, this.m_blue, this.m_transparency)
121 call TriggerSleepAction(this.m_rate / 2.00)
122 //call SetUnitVertexColorBJ(H2Unit(this.m_object), 100.0, 100.0, 100.0, 0.0)
123 endmethod
124
125 private method indicateObject takes nothing returns nothing
126 if (this.m_objectType == AIndicator.objectTypeImage) then
127 call this.indicateImage()
128 elseif (this.m_objectType == AIndicator.objectTypeTextTag) then
129 call this.indicateTextTag()
130 elseif (this.m_objectType == AIndicator.objectTypeUnit) then
131 call this.indicateUnit()
132 debug else
133 debug call this.print("Invalid object type " + I2S(this.m_objectType) + ".")
134 endif
135 endmethod
136
137 private method inrcreaseElapsedTime takes nothing returns nothing
138 set this.m_elapsedTime = this.m_elapsedTime + this.m_rate
139 if (this.m_elapsedTime >= this.m_time) then
140 call this.enable(false)
141 endif
142 endmethod
143
144 private static method triggerActionIndicateObject takes nothing returns nothing
145 local trigger triggeringTrigger = GetTriggeringTrigger()
146 local AIndicator this = AHashTable.global().handleInteger(triggeringTrigger, "this")
147 if (this.m_object != null) then
148 call this.indicateObject()
149 call this.inrcreaseElapsedTime()
150 else
151 call this.enable(false)
152 endif
153 set triggeringTrigger = null
154 endmethod
155
156 private method reset takes nothing returns nothing
157 if (this.m_objectType == AIndicator.objectTypeImage) then
158 //call SetImageColorBJ(this.m_object, 100.0, 100.0, 100.0, 0.0)
159 elseif (this.m_objectType == AIndicator.objectTypeTextTag) then
160 //call SetTextTagColorBJ(this.m_object, 100.0, 100.0, 100.0, 0.0)
161 elseif (this.m_objectType == AIndicator.objectTypeUnit) then
162 //call SetUnitVertexColorBJ(this.m_object, 100.0, 100.0, 100.0, 0.0)
163 endif
164 endmethod
165
166 private method createRefreshTrigger takes nothing returns nothing
167 local event triggerEvent
168 local triggeraction triggerAction
169 set this.m_refreshTrigger = CreateTrigger()
170 set triggerEvent = TriggerRegisterTimerEvent(this.m_refreshTrigger, this.m_rate, true)
171 set triggerAction = TriggerAddAction(this.m_refreshTrigger, function AIndicator.triggerActionIndicateObject)
172 call AHashTable.global().setHandleInteger(this.m_refreshTrigger, "this", this)
173 set triggerEvent = null
174 set triggerAction = null
175 endmethod
176
177 public static method create takes handle object, integer objectType, real rate, real time, real red, real green, real blue, real transparency returns AIndicator
178 local AIndicator this = AIndicator.allocate()
179 //dynamic members
180 set this.m_object = object
181 set this.m_objectType = objectType
182 set this.m_rate = rate
183 set this.m_time = time
184 set this.m_red = red
185 set this.m_green = green
186 set this.m_blue = blue
187 set this.m_transparency = transparency
188 //members
189 set this.m_elapsedTime = 0.00
190 set this.m_firstTime = true
191
192 call this.createRefreshTrigger()
193 return this
194 endmethod
195
196 private method destroyRefreshTrigger takes nothing returns nothing
197 call AHashTable.global().destroyTrigger(this.m_refreshTrigger)
198 set this.m_refreshTrigger = null
199 endmethod
200
201 public method onDestroy takes nothing returns nothing
202 //dynamic members
203 set this.m_object = null
204
205 call this.destroyRefreshTrigger()
206 endmethod
207 endstruct
208
209 endlibrary